package com.jahooty.blocks;

import com.jahooty.blocks.ore.BlockAluminumOre;
import com.jahooty.blocks.ore.BlockChromiumOre;
import com.jahooty.blocks.ore.BlockCopperOre;
import com.jahooty.blocks.ore.BlockGermaniumOre;
import com.jahooty.blocks.ore.BlockLeadOre;
import com.jahooty.blocks.ore.BlockNickelOre;
import com.jahooty.blocks.ore.BlockPlatinumOre;
import com.jahooty.blocks.ore.BlockSilverOre;
import com.jahooty.blocks.ore.BlockSulfurOre;
import com.jahooty.blocks.ore.BlockTinOre;
import com.jahooty.blocks.ore.BlockTitaniumOre;
import com.jahooty.blocks.ore.BlockTungstenOre;
import com.jahooty.blocks.ore.BlockUraniumOre;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

/**
 * Class that will contain all of the blocks that are added by the
 * Jahooty mod.  This is a helper class rather than having to manage
 * all of the blocks individually.
 *
 * @author Michael
 */
public class JahootyBlocks
{
    private static JahootyBlocks mInstance;

    // Ores

    public static BlockAluminumOre aluminum_ore;

    public static BlockChromiumOre chromium_ore;

    public static BlockCopperOre copper_ore;

    public static BlockGermaniumOre germanium_ore;

    public static BlockLeadOre lead_ore;

    public static BlockNickelOre nickel_ore;

    public static BlockPlatinumOre platinum_ore;

    public static BlockSilverOre silver_ore;

    public static BlockSulfurOre sulfur_ore;

    public static BlockTinOre tin_ore;

    public static BlockTitaniumOre titanium_ore;

    public static BlockTungstenOre tungsten_ore;

    public static BlockUraniumOre uranium_ore;

    /**
     * Static public method that is used to get the singleton instance
     * of this class.
     *
     * @return Singleton instance of the JahootyModBlocks class
     */
    public static JahootyBlocks getInstance()
    {
        if ( JahootyBlocks.mInstance == null )
        {
            JahootyBlocks.mInstance = new JahootyBlocks();
        }

        return JahootyBlocks.mInstance;
    }

    /**
     * Method that is used to initialize all of the blocks.  Any new blocks
     * will be added here first in order to exist in the world.
     */
    public void initializeBlocks()
    {
        this.initializeOres();

        this.registerOres();

        this.changeExistingOres();
    }

    /**
     * Method that is used to register the ores to be seen in the player inventory.  If this
     * is not called, then the ores will exist in the game and world, but not look right in the
     * player inventory.
     */
    public void registerOresInInventory()
    {
        Minecraft minecraft = Minecraft.getMinecraft();

        if ( minecraft == null )
        {
            return;
        }

        RenderItem renderItem = minecraft.getRenderItem();

        if ( renderItem == null )
        {
            return;
        }

        ItemModelMesher itemModelMesher = renderItem.getItemModelMesher();

        if ( itemModelMesher == null )
        {
            return;
        }

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.aluminum_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockAluminumOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.chromium_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockChromiumOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.copper_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockCopperOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.germanium_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockGermaniumOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.lead_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockLeadOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.nickel_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockNickelOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.platinum_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockPlatinumOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.silver_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockSilverOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.sulfur_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockSulfurOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.tin_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockTinOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.titanium_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockTitaniumOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.tungsten_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockTungstenOre.REGISTERED_NAME,
                                                             "inventory" ) );

        itemModelMesher.register( Item.getItemFromBlock( JahootyBlocks.uranium_ore ),
                                  0,
                                  new ModelResourceLocation( "jahootymod:" + BlockUraniumOre.REGISTERED_NAME,
                                                             "inventory" ) );
    }

    /**
     * Private method that will change some of the features of the ores
     * that are provided by vanilla Minecraft in order to make them
     * match the look and feel of the mod.
     */
    private void changeExistingOres()
    {

    }

    /**
     * Private method that will load all of the ores that
     * are added by the Jahooty mod.
     */
    private void initializeOres()
    {
        JahootyBlocks.aluminum_ore = new BlockAluminumOre();

        JahootyBlocks.chromium_ore = new BlockChromiumOre();

        JahootyBlocks.copper_ore = new BlockCopperOre();

        JahootyBlocks.germanium_ore = new BlockGermaniumOre();

        JahootyBlocks.lead_ore = new BlockLeadOre();

        JahootyBlocks.nickel_ore = new BlockNickelOre();

        JahootyBlocks.platinum_ore = new BlockPlatinumOre();

        JahootyBlocks.silver_ore = new BlockSilverOre();

        JahootyBlocks.sulfur_ore = new BlockSulfurOre();

        JahootyBlocks.tin_ore = new BlockTinOre();

        JahootyBlocks.titanium_ore = new BlockTitaniumOre();

        JahootyBlocks.tungsten_ore = new BlockTungstenOre();

        JahootyBlocks.uranium_ore = new BlockUraniumOre();
    }

    /**
     * Private method that will register the ores in to the game so that
     * they can be used in-game.
     */
    private void registerOres() {
        GameRegistry.registerBlock( JahootyBlocks.aluminum_ore,
                                    BlockAluminumOre.REGISTERED_NAME);

        GameRegistry.registerBlock( JahootyBlocks.chromium_ore,
                                    BlockChromiumOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.copper_ore,
                                    BlockCopperOre.REGISTERED_NAME);

        GameRegistry.registerBlock( JahootyBlocks.germanium_ore,
                                    BlockGermaniumOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.lead_ore,
                                    BlockLeadOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.nickel_ore,
                                    BlockNickelOre.REGISTERED_NAME);

        GameRegistry.registerBlock( JahootyBlocks.platinum_ore,
                                    BlockPlatinumOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.silver_ore,
                                    BlockSilverOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.sulfur_ore,
                                    BlockSulfurOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.tin_ore,
                                    BlockTinOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.titanium_ore,
                                    BlockTitaniumOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.tungsten_ore,
                                    BlockTungstenOre.REGISTERED_NAME );

        GameRegistry.registerBlock( JahootyBlocks.uranium_ore,
                                    BlockUraniumOre.REGISTERED_NAME );
    }
}